#define _CRT_SECURE_NO_WARNINGS   1

#include<iostream>

using namespace std;

class Solution
{
public:
	int x[10];
	int sum = 0;
	bool place(int k)
	{
		for (int i = 1; i<k; i++)
		{
			if (x[i] == x[k] || abs(x[i] - x[k]) == abs(i - k))
				return 0;
		}
		return 1;
	}
	void DFS(int k, int n)
	{
		if (k>n)
			sum++;
		else
		{
			for (int i = 1; i <= n; i++)
			{
				x[k] = i;
				if (place(k))
					DFS(k + 1, n);
			}
		}
	}
	int Nqueen(int n)
	{
		DFS(1, n);
		return sum;
	}
};

int main()
{
	Solution sol;
	int n;
	cin >> n;
	cout << sol.Nqueen(n) << endl;
	return 0;
}